<template>
<div>

  <myproducts v-for="(item,index) in list"
   :key="item.id"
   :title="item.proname"
       :price="item.proprice"
   :intro="item.info"
   :index="index"
   @kanprice="kanFn"
   
   ></myproducts>
   <!-- @kanprice="kanFn"这个是用来子传父的 -->
   <!-- 这个index是遍历的下标 -->
</div>
</template>

<script>
import myproducts from './myproducts.vue'
export default {
data () {
    return {
        list: [
    { id: 1, proname: "超级好吃的棒棒糖", proprice: 18.8, info: '开业大酬宾, 全场8折' },
    { id: 2, proname: "超级好吃的大鸡腿", proprice: 34.2, info: '好吃不腻, 快来买啊' },
    { id: 3, proname: "超级无敌的冰激凌", proprice: 14.2, info: '炎热的夏天, 来个冰激凌了' },
],
    }
},
methods: {
    kanFn(index,price){
        if(this.list[index].proprice<1){
            return alert('不要砍了')
        }
        //指向数组的下标的价格=数组下标的价格减去价格，price是子组件btn里面的1
this.list[index].proprice=(this.list[index].proprice-price).toFixed(2)
    }
},
components: {
    myproducts
}
}
</script>

<style>

</style>